package com.example.shixunandjavagotoyangchen.BoosYang.Day002;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersAdpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersBean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersModel;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1103.SneakersPresenter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1104.WomenswearAdpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1104.WomenswearBean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1104.WomenswearContion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1104.WomenswearModel;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1104.WomenswearPresenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay002_1104 extends BasterFragment  implements OnRefreshLoadMoreListener, WomenswearContion.vier {

    public static SmartRefreshLayout WomenswearSmartRefreshLayout;
    private RecyclerView WomenswearRecyclerView;
    public boolean isning=true;
    public WomenswearAdpter adpter;
    public WomenswearPresenter presenter;
    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day002_1104;
    }

    @Override
    public void initView() {

        WomenswearSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Womenswear_SmartRefreshLayout);
        WomenswearRecyclerView = (RecyclerView) findViewById(R.id.Womenswear_RecyclerView);
        WomenswearRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
        WomenswearSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        presenter = new WomenswearPresenter(this,new WomenswearModel());
        presenter.womenswearing("Home_zidingyi.php");
    }

    @Override
    public void initDate() {

    }

    @Override
    public void getvier(List<WomenswearBean.ShujuBean> dataBeans) {
        WomenswearSmartRefreshLayout.finishLoadMore();
        WomenswearSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new WomenswearAdpter(dataBeans);
            WomenswearRecyclerView.setAdapter(adpter);
        }else {
            if (isning){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        isning =false;
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        if (isning){
            Log.i("aaa","la1");
        }
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();

    }
}
